{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="row">
                <!--搜索框开始-->
                <div class="col-sm-12">
                    <div class="layui-form layui-form-item">
                        <div class="layui-col-md6 layui-input-inline">
                            <input type="text" id="key" class="layui-input search" name="key" value="" placeholder="店铺名/用户名"/>
                        </div>
                        <div class="layui-input-inline">
                            <button class="layui-btn" lay-submit="" lay-filter="LAY-search">立即搜索</button>
                            <button  class="layui-btn layui-btn-normal" id="empty"  lay-submit="" lay-filter="LAY-search">重置</button>
                        </div>
                    </div>
                </div>
                <!--搜索框结束-->
            </div>
            <div class="hr-line-dashed"></div>

            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="demo"></table>
                    <!--图片模板-->
                    <script type="text/html" id="img1Tpl">
                        <img src="{{d.shop_facade_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--图片模板-->
                    <script type="text/html" id="img2Tpl">
                        <img src="{{d.shop_ldentity_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--图片模板-->
                    <script type="text/html" id="img3Tpl">
                        <img src="{{d.shop_hand_img}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  />
                    </script>
                    <!--操作模板-->
                    <script type="text/html" id="opeBar">
                        <a href="javascript:;" onclick="wk.layer_show('审核', '{:url('checkcheck')}?shop_id={{d.shop_id}}&user_id={{d.user_id}}')" class="btn btn-warning btn-xs m-r-xs" title="审核">审核</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    //layui渲染数据表格
    layui.use('table', function () {
        var table = layui.table
            , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("shop/check")}'
            ,response: {
                statusCode: 220 //成功的状态码，默认：0
            }
            , page: true
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            , cellMinWidth: 150
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: 10
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type:'numbers', width: 80, title: '序号'}
                , {field: 'user_username', width: '', title: '申请人', align: 'center'}
                // , {field: 'user_image', width: 90, title: '头像', align: 'center', templet: '#imgTpl'}
                , {field: 'shop_name', width: '', title: '店铺名', align: 'center'}
                , {field: 'shop_range', width: '', title: '经营范围', align: 'center'}
                , {field: 'shop_contact', width: '', title: '手机号', align: 'center'}
                , {field: 'sheng', width: '', title: '省', align: 'center'}
                , {field: 'shi', width: '', title: '市', align: 'center'}
                , {field: 'qu', width: '', title: '区', align: 'center'}
                , {field: 'shop_address',width: '', title: '地址', align: 'center'}
                , {field: 'shop_facade_img',width: '', title: '身份证正面', align: 'center',templet:"#img1Tpl"}
                , {field: 'shop_ldentity_img',width: '', title: '身份证反面', align: 'center',templet:"#img2Tpl"}
                , {field: 'shop_hand_img',width: '', title: '营业执照三证合一', align: 'center',templet:"#img3Tpl"}
                , {field: 'shop_remark', width: '', title: '备注', align: 'center'}
                , {field: 'username', width: '', title: '上级代理', align: 'center'}
                , {fixed: 'right', width: 100, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]],
            done:function () {
               $('.img-circle').viewer();
            }
        });
    });
    function check(shop_id,user_id) {
        layer.prompt({
            formType: 2,
            value: ' ',
            title: '审核是否通过，驳回请填写原因',
            area: ['800px', '350px'],
            btn: ['通过', '驳回'],
            maxlength:100,
            btn2:function(index, elem){
                var value = layui.jquery('#layui-layer'+index + " .layui-layer-input").val();
                if (!value || value == ' ') {
                    wk.error('驳回请填写原因');
                    return false;　　// 如果value为空，停止继续执行
                }
                send(shop_id,user_id,4,value);
                layer.close(index);
            }
        },function(value, index, elem){
            send(shop_id,user_id,2,value);
            layer.close(index);
        });
    }
    function send(shop_id,user_id,type,msg){
        $.ajax({
            url: "{:url('doCheck')}",
            type: "post",
            dataType: "json",
            data: {shop_id:shop_id,user_id:user_id,type:type,msg:msg,temp:101},
            success: function (res) {
                if(res.code == 200){
                    layer.msg(res.msg,{icon:1,time:1500,shade: 0.1},function(){
                        //重载当前页表格
                        $(".layui-laypage-btn").click();
                    });
                } else if (res.code == 100){
                    layer.msg(res.msg,{icon:2,time:1500,shade: 0.1});
                }
            }
        });
    }
</script>
</body>
</html>